#ifndef UPGRADEFORM_H
#define UPGRADEFORM_H

#include <QWidget>
#include <QFileDialog>
#include <QMessageBox>
#include <QTimer>
#include <QIntValidator>

#include "datapack.h"
#include "msgparse.h"
#include "fileunit.h"

#define PACK_LEN 200


namespace Ui {
class UpgradeForm;
}

class UpgradeForm : public QWidget
{
    Q_OBJECT

public:
    explicit UpgradeForm(QWidget *parent = nullptr);
    ~UpgradeForm();
    void init(void);

    void sendPackSize(uint16_t size,uint16_t packSize,uint32_t ver);
    void sendBin(uint16_t num,uint8_t *buf,uint16_t len);
    void getBinMsg(void);
private:
    Ui::UpgradeForm *ui;

    uint32_t version;
    QString filePath;
    FileUnit fileUnit;
    QByteArray binFile;
    int binSize;
    int packTotal;
    int currentIndex;
    int currentPackSize;
    uint8_t *bin;
    QTimer *updataStatTimer; // 查看更新是否正常
protected:
    void showEvent(QShowEvent *event); // 窗体显示在屏幕上时
    void hideEvent(QHideEvent *event); // 窗体从屏幕上消失时，(包括最小化，不包括被遮挡)

signals:
    //void serialWriteMsg(DataPack *data);
    void serialWriteData(uint8_t *data,int len);    // 串口数据接受的槽函数

private slots:
    //void serialReadData(char *data,qint64 len);
    void serialReadMsg(DataPack *data);             // 串口数据接受的槽函数
    void on_fileCheck_clicked();

    void on_startSendBin_clicked();
    void updataStatTimerCallBack(void);
};

#endif // UPGRADEFORM_H
